<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <!-- 引入VUE-->
    <script type="text/javascript" src="../js/vue.js"></script>
</head>

<body>
    <div id="root">
        <h2>欢迎来到 {{ name }}</h2>
        <div>numbers.num1 = {{ numbers.num1 }}</div>
        <div>numbers.num2 = {{ numbers.num2 }}</div>
        <button @click='num1Add'>点我num1 ++</button>
        <button @click='num2Add'>点我num2 ++</button>
    </div>
</body>
<script>
    Vue.config.productionTip = false

    const vm = new Vue({
        el: '#root',
        data: {
            name: '尚硅谷',
            numbers: {
                num1: 1,
                num2: 2
            }
        },
        methods: {
            num1Add() {
                this.numbers.num1++;
            },
            num2Add() {
                this.numbers.num2++;
            }
        },
        computed: {
            info() {
                return this.name
            }
        },
        watch: {
            name: {
                handler(newValue, oldValue) {
                    console.log('属性被修改');
                },
                // immediate: true // 初始化时执行handler,
            },
            // 简写形式
            info() {
                console.log('info被修改');
            },
            // 完整形式
            // 深度监控
            'numbers': {
                handler() {
                    console.log('深度监控 this.numbers', this.numbers);
                },
                deep: true
            },
            'numbers.num1': {
                handler() {
                    console.log('深度监控 this.numbers.num1', this.numbers.num1);
                }
            }

        }
    })
    // vm.$watch('info', {
    //     handler(newValue, oldValue) {
    //         console.log('属性被修改');
    //     },
    // })
</script>

</html>